﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainClient
{
    public partial class frmRecoveryDB : Form
    {
        public frmRecoveryDB()
        {
            InitializeComponent();
        }


        private void frmRecoveryDB_Load(object sender, EventArgs e)
        {

        }

        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            this.ofdDBFile.InitialDirectory = Application.StartupPath.ToString()+"\\Backup";
            this.ofdDBFile.Filter = "数据库备份文件(*.bak)|*.bak";
            this.ofdDBFile.FilterIndex = 0;
            this.ofdDBFile.RestoreDirectory = true;
            this.ofdDBFile.ShowHelp = false;
            this.ofdDBFile.Title = "选择数据库备份文件";
            if (this.ofdDBFile.ShowDialog() == DialogResult.OK)
            {
                this.txtFilePath.Text = this.ofdDBFile.FileName;
            }
        }

        private void btnRecoveryDB_Click(object sender, EventArgs e)
        {
            Console.WriteLine("恢复目标目录：" + this.txtFilePath.Text.Trim());
            if (System.IO.File.Exists(this.txtFilePath.Text.Trim()))
            {
                DataAccess.DBDAO dbDAO = new DataAccess.DBDAO();
                dbDAO.RecoveryDB(this.txtFilePath.Text.Trim());
            }
            else
            {
                MessageBox.Show("目标文件不存在！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
